<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libschc: bit_operations.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libschc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">bit_operations.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="bit__operations_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * (c) 2018 - idlab - UGent - imec</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Bart Moons</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * This file is part of the SCHC stack implementation</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#ifndef _SCHC_BIT_H_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#define _SCHC_BIT_H_</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160; </div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160; </div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160; </div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="schc_8h.html">schc.h</a>&quot;</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="bit__operations_8h.html#a4c1e0708f6f9b121ca602cd8ceddd670">   20</a></span>&#160;<span class="preprocessor">#define BYTES_TO_BITS(x)    (x * 8)</span></div>
<div class="line"><a name="l00021"></a><span class="lineno"><a class="line" href="bit__operations_8h.html#ac5eb6b4755b74c50cb76155d08b6e2ff">   21</a></span>&#160;<span class="preprocessor">#define BITS_TO_BYTES(x)    (((x) == 0) ? 0 : (((x) - 1) / 8 + 1)) // bytes required for a number of bits</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160; </div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment">// sets bits at a certain position in a bit array</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#a6ca8acc21387487f5a65244eee7657ad">set_bits</a>(uint8_t A[], uint32_t pos, uint32_t len);</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="comment">// get bits at a certain position in a bit array</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;uint32_t <a class="code" href="bit__operations_8h.html#ac145c54c244fb53f1fb266113f483d54">get_bits</a>(<span class="keyword">const</span> uint8_t A[], uint32_t pos, uint8_t len);</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160; </div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="comment">// clear bits at a certain position in a bit array</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#a3821f50623047fb93ed4b820fd4a1b8a">clear_bits</a>(uint8_t A[], uint32_t pos, uint32_t len);</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment">// copy bits to a certain position in a bit array from another array</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#aa74d3f4edb3fbd2704f24343a2e50813">copy_bits</a>(uint8_t DST[], uint32_t dst_pos, <span class="keyword">const</span> uint8_t SRC[], uint32_t src_pos, uint32_t len);</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="comment">// void copy_bits_BIG_END(uint8_t DST[], uint32_t dst_pos, const uint8_t SRC[], uint32_t src_pos, uint32_t len);</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160; </div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="comment">// compare two bit arrays</span></div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;uint8_t <a class="code" href="bit__operations_8h.html#a9dfca8d34f44271dd48ef2c3be2f0092">compare_bits</a>(<span class="keyword">const</span> uint8_t SRC1[], <span class="keyword">const</span> uint8_t SRC2[], uint32_t len);</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;uint8_t <a class="code" href="bit__operations_8h.html#a8e148c4d5810b49b365e71a7ef7337e7">compare_bits_aligned</a>(<span class="keyword">const</span> uint8_t SRC1[], uint16_t pos1, <span class="keyword">const</span> uint8_t SRC2[], uint16_t pos2, uint32_t len);</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;uint8_t <a class="code" href="bit__operations_8h.html#ac419537c6b944dac4508bb2535e1b633">compare_bits_BIG_END</a>(uint8_t SRC1[], uint8_t SRC2[], uint32_t len);</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160; </div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<span class="comment">// shift a number of bits to the left</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#a6ebd634daa417f0d054b15983d0703af">shift_bits_left</a>(uint8_t SRC[], uint16_t len, uint32_t shift);</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160; </div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160; <span class="comment">// shift a number of bits to the right</span></div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#afadff313aab0bbe2ed79ce72885735c3">shift_bits_right</a>(uint8_t SRC[], uint16_t len, uint32_t shift);</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="comment">// logic xor two bit arrays</span></div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#a9858cf5fc58daff568ba07a5d264989d">xor_bits</a>(uint8_t DST[], uint8_t SRC1[], uint8_t SRC2[], uint32_t len);</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160; </div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="comment">// logic and two bit arrays</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#a5e6bd75bf5871176bb38d7e382372f28">and_bits</a>(uint8_t DST[], uint8_t SRC1[], uint8_t SRC2[], uint32_t len);</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160; </div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="comment">// print an array of bits</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;<span class="keywordtype">void</span> <a class="code" href="bit__operations_8h.html#a963c3f1e2f40087703e826a454198faa">print_bitmap</a>(<span class="keyword">const</span> uint8_t bitmap[], uint32_t length);</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160; </div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;<span class="comment">// get the ceiled length in bytes</span></div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;uint8_t <a class="code" href="bit__operations_8h.html#a56ab5e62da3e4cde30d216b7e0b53b2a">get_number_of_bytes_from_bits</a>(uint16_t number_of_bits);</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160; </div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;<span class="comment">// return the number of 1-bits in the value</span></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;uint32_t <a class="code" href="bit__operations_8h.html#a908d1e823f59e9d52bb7eec00e666959">get_required_number_of_bits</a>(uint32_t value);</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="comment">// return the starting bit of a value</span></div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;uint8_t <a class="code" href="bit__operations_8h.html#a43ead7431c1b8bd21806927b306fb7fd">get_position_in_first_byte</a>(uint8_t value);</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160; </div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;<span class="comment">// remove padding</span></div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;uint8_t <a class="code" href="bit__operations_8h.html#afa77e854f2ae60f5126d75270d28a059">padded</a>(<a class="code" href="structschc__bitarray__t.html">schc_bitarray_t</a>* bit_array);</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160; </div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160; </div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;}</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160; </div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;<span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="abit__operations_8h_html_afadff313aab0bbe2ed79ce72885735c3"><div class="ttname"><a href="bit__operations_8h.html#afadff313aab0bbe2ed79ce72885735c3">shift_bits_right</a></div><div class="ttdeci">void shift_bits_right(uint8_t SRC[], uint16_t len, uint32_t shift)</div><div class="ttdoc">shift a number of bits to the right</div><div class="ttdef"><b>Definition:</b> bit_operations.c:202</div></div>
<div class="ttc" id="astructschc__bitarray__t_html"><div class="ttname"><a href="structschc__bitarray__t.html">schc_bitarray_t</a></div><div class="ttdef"><b>Definition:</b> schc.h:32</div></div>
<div class="ttc" id="abit__operations_8h_html_aa74d3f4edb3fbd2704f24343a2e50813"><div class="ttname"><a href="bit__operations_8h.html#aa74d3f4edb3fbd2704f24343a2e50813">copy_bits</a></div><div class="ttdeci">void copy_bits(uint8_t DST[], uint32_t dst_pos, const uint8_t SRC[], uint32_t src_pos, uint32_t len)</div><div class="ttdoc">copy bits to a certain position in a bit array from another array big endian</div><div class="ttdef"><b>Definition:</b> bit_operations.c:82</div></div>
<div class="ttc" id="abit__operations_8h_html_a6ca8acc21387487f5a65244eee7657ad"><div class="ttname"><a href="bit__operations_8h.html#a6ca8acc21387487f5a65244eee7657ad">set_bits</a></div><div class="ttdeci">void set_bits(uint8_t A[], uint32_t pos, uint32_t len)</div><div class="ttdoc">sets bits at a certain position in a bit array big endian</div><div class="ttdef"><b>Definition:</b> bit_operations.c:25</div></div>
<div class="ttc" id="abit__operations_8h_html_a9dfca8d34f44271dd48ef2c3be2f0092"><div class="ttname"><a href="bit__operations_8h.html#a9dfca8d34f44271dd48ef2c3be2f0092">compare_bits</a></div><div class="ttdeci">uint8_t compare_bits(const uint8_t SRC1[], const uint8_t SRC2[], uint32_t len)</div><div class="ttdoc">compare two bit arrays</div><div class="ttdef"><b>Definition:</b> bit_operations.c:108</div></div>
<div class="ttc" id="abit__operations_8h_html_a3821f50623047fb93ed4b820fd4a1b8a"><div class="ttname"><a href="bit__operations_8h.html#a3821f50623047fb93ed4b820fd4a1b8a">clear_bits</a></div><div class="ttdeci">void clear_bits(uint8_t A[], uint32_t pos, uint32_t len)</div><div class="ttdoc">clear bits at a certain position in a bit array big endian</div><div class="ttdef"><b>Definition:</b> bit_operations.c:63</div></div>
<div class="ttc" id="abit__operations_8h_html_a5e6bd75bf5871176bb38d7e382372f28"><div class="ttname"><a href="bit__operations_8h.html#a5e6bd75bf5871176bb38d7e382372f28">and_bits</a></div><div class="ttdeci">void and_bits(uint8_t DST[], uint8_t SRC1[], uint8_t SRC2[], uint32_t len)</div><div class="ttdoc">logical AND two bit arrays</div><div class="ttdef"><b>Definition:</b> bit_operations.c:244</div></div>
<div class="ttc" id="abit__operations_8h_html_ac145c54c244fb53f1fb266113f483d54"><div class="ttname"><a href="bit__operations_8h.html#ac145c54c244fb53f1fb266113f483d54">get_bits</a></div><div class="ttdeci">uint32_t get_bits(const uint8_t A[], uint32_t pos, uint8_t len)</div><div class="ttdoc">get bits at a certain position in a bit array</div><div class="ttdef"><b>Definition:</b> bit_operations.c:42</div></div>
<div class="ttc" id="abit__operations_8h_html_a56ab5e62da3e4cde30d216b7e0b53b2a"><div class="ttname"><a href="bit__operations_8h.html#a56ab5e62da3e4cde30d216b7e0b53b2a">get_number_of_bytes_from_bits</a></div><div class="ttdeci">uint8_t get_number_of_bytes_from_bits(uint16_t number_of_bits)</div><div class="ttdoc">get the number of bytes required to store this amount of bits</div><div class="ttdef"><b>Definition:</b> bit_operations.c:274</div></div>
<div class="ttc" id="aschc_8h_html"><div class="ttname"><a href="schc_8h.html">schc.h</a></div></div>
<div class="ttc" id="abit__operations_8h_html_a43ead7431c1b8bd21806927b306fb7fd"><div class="ttname"><a href="bit__operations_8h.html#a43ead7431c1b8bd21806927b306fb7fd">get_position_in_first_byte</a></div><div class="ttdeci">uint8_t get_position_in_first_byte(uint8_t value)</div><div class="ttdoc">get the starting bit of a value</div><div class="ttdef"><b>Definition:</b> bit_operations.c:305</div></div>
<div class="ttc" id="abit__operations_8h_html_ac419537c6b944dac4508bb2535e1b633"><div class="ttname"><a href="bit__operations_8h.html#ac419537c6b944dac4508bb2535e1b633">compare_bits_BIG_END</a></div><div class="ttdeci">uint8_t compare_bits_BIG_END(uint8_t SRC1[], uint8_t SRC2[], uint32_t len)</div></div>
<div class="ttc" id="abit__operations_8h_html_a6ebd634daa417f0d054b15983d0703af"><div class="ttname"><a href="bit__operations_8h.html#a6ebd634daa417f0d054b15983d0703af">shift_bits_left</a></div><div class="ttdeci">void shift_bits_left(uint8_t SRC[], uint16_t len, uint32_t shift)</div><div class="ttdoc">shift a number of bits to the left</div><div class="ttdef"><b>Definition:</b> bit_operations.c:180</div></div>
<div class="ttc" id="abit__operations_8h_html_a908d1e823f59e9d52bb7eec00e666959"><div class="ttname"><a href="bit__operations_8h.html#a908d1e823f59e9d52bb7eec00e666959">get_required_number_of_bits</a></div><div class="ttdeci">uint32_t get_required_number_of_bits(uint32_t value)</div><div class="ttdoc">get the number of bits required to store a value</div><div class="ttdef"><b>Definition:</b> bit_operations.c:288</div></div>
<div class="ttc" id="abit__operations_8h_html_afa77e854f2ae60f5126d75270d28a059"><div class="ttname"><a href="bit__operations_8h.html#afa77e854f2ae60f5126d75270d28a059">padded</a></div><div class="ttdeci">uint8_t padded(schc_bitarray_t *bit_array)</div><div class="ttdoc">remove padding</div><div class="ttdef"><b>Definition:</b> bit_operations.c:322</div></div>
<div class="ttc" id="abit__operations_8h_html_a9858cf5fc58daff568ba07a5d264989d"><div class="ttname"><a href="bit__operations_8h.html#a9858cf5fc58daff568ba07a5d264989d">xor_bits</a></div><div class="ttdeci">void xor_bits(uint8_t DST[], uint8_t SRC1[], uint8_t SRC2[], uint32_t len)</div><div class="ttdoc">logical XOR two bit arrays</div><div class="ttdef"><b>Definition:</b> bit_operations.c:227</div></div>
<div class="ttc" id="abit__operations_8h_html_a8e148c4d5810b49b365e71a7ef7337e7"><div class="ttname"><a href="bit__operations_8h.html#a8e148c4d5810b49b365e71a7ef7337e7">compare_bits_aligned</a></div><div class="ttdeci">uint8_t compare_bits_aligned(const uint8_t SRC1[], uint16_t pos1, const uint8_t SRC2[], uint16_t pos2, uint32_t len)</div><div class="ttdoc">compare two bit arrays with starting point</div><div class="ttdef"><b>Definition:</b> bit_operations.c:133</div></div>
<div class="ttc" id="abit__operations_8h_html_a963c3f1e2f40087703e826a454198faa"><div class="ttname"><a href="bit__operations_8h.html#a963c3f1e2f40087703e826a454198faa">print_bitmap</a></div><div class="ttdeci">void print_bitmap(const uint8_t bitmap[], uint32_t length)</div><div class="ttdoc">print a bitmap</div><div class="ttdef"><b>Definition:</b> bit_operations.c:259</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
